package com.exchange.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exchange.entity.pojo.CardDisplay;
import com.exchange.service.CardDisplayService;
import com.exchange.service.CardRollService;
import com.exchange.until.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 周佳辉
 * @date 2024/4/26
 */
@RestController
@RequestMapping("/jeecg-boot")
@Tag(name = "活动管理")
public class ActivityController {

    @Autowired
    private CardDisplayService cardDisplayService;

    @Autowired
    private CardRollService cardRollService;

    @GetMapping("/activity")
    @Operation(summary = "查询活动")
    public Result<Page<CardDisplay>> cardList(@RequestParam(value = "offset",defaultValue = "1")Integer offset,
                                              @RequestParam(value = "pagesize",defaultValue = "3")Integer pagesize){
        Page<CardDisplay> page = this.cardDisplayService.CardKist(offset,pagesize);
        return new Result<>(200,"查询成功",true,page);
    }

    /**
     * 拿到活动的id编号
     * @param cardDisplay
     * @param token
     * @return
     */
    @PostMapping("/can")
    @Operation(summary = "参与活动")
    public Result can(@RequestBody CardDisplay cardDisplay,
                      @RequestHeader String token){
        System.err.println("cardDisplay:"+cardDisplay);
        this.cardRollService.cardRoll(cardDisplay,token);
        return new Result(200,"参与成功",true,null);
    }
}
